package Test3;

import java.util.Scanner;
import java.util.ArrayList;

public class Main1{
    public static void main(String args[]){
        Scanner sc = new Scanner (System.in);
        ArrayList<String> namelist = new ArrayList <String> ();


        String b ;
        while(!"end".equals(b=sc.nextLine())) {
            namelist.add(b);
        }//数组列表赋值
        for(int i = 0;i<namelist.size()-1;i++){//i<namelist.size()-1?
            for(int j = namelist.size()-1 ;j>i;j-- ){
                if(namelist.get(i).equals(namelist.get(j)))
                    namelist.remove(j);
            }
        }//每个名字只能存1次。
        System.out.println(namelist);


        int c = sc.nextInt();
        String ie = sc.nextLine();
        String e = sc.nextLine();
        namelist.add(c,e);
        int n = sc.nextInt();
        String n1 = sc.nextLine();//读掉回车
        namelist.remove(n);
        System.out.println(namelist);


        int k = -1;
        String name1 = sc.nextLine();
        String name2 = sc.nextLine();
        for(int a = 0;a<namelist.size();a++){
            if(name1.equals(namelist.get(a)))
                k = a;
            //不能加break；
        }
        System.out.println("k="+k);


        if(k>=0)namelist.set(k,name2);
        else namelist.add(name2);
        System.out.println(namelist);
    }
}

